package com.mushuilingfeng.ddd.user.infrastructure.verifycode;

import com.mushuilingfeng.ddd.user.domain.base.DomainArgumentException;
import com.mushuilingfeng.ddd.user.domain.base.VerifyCodeType;
import com.mushuilingfeng.ddd.user.domain.base.service.VerifyCodeService;

/**
 * @author
 * @date 2024/9/29
 */
public abstract class AbstractVerifyCodeService implements VerifyCodeService {

    public abstract boolean canProcess(VerifyCodeType type);

    @Override
    public void sendVerifyCode(String tel, VerifyCodeType type) {
        if (!canProcess(type)) {
            throw new DomainArgumentException("不能处理" + type + "类型的验证码");
        }
        sendVerifyCode(tel);
    }

    abstract void sendVerifyCode(String tel);

    @Override
    public boolean verifyCode(String tel, VerifyCodeType type, String code) {
        if (!canProcess(type)) {
            throw new DomainArgumentException("不能处理" + type + "类型的验证码");
        }
        return verifyCode(tel, code);
    }

    abstract boolean verifyCode(String tel, String code);
}
